using System.Linq;
using Rhizome.Contract;
using System.Diagnostics;

namespace Rhizome.Model
{
    public class OrCriterion<TPlant> : AggregateCriterionBase<TPlant>
    {
        public OrCriterion(params ICriterion[] criterions) : base(criterions)
        {
        }

        public OrCriterion()
        {
        }

        /// <summary>
        /// XAML "macro".
        /// Adds specific value to Criterions
        /// </summary>
		public ICriterion If
        {
			[DebuggerStepThrough]
			get { return Criterions.FirstOrDefault(); }
			[DebuggerStepThrough]
			set { Criterions.Add(value); }
        }

         /// <summary>
        /// XAML "macro".
        /// Adds specific value to Criterions
        /// </summary>
        public ICriterion Or
        {
			[DebuggerStepThrough]
			get { return Criterions.Skip(1).FirstOrDefault(); }
			[DebuggerStepThrough]
			set { Criterions.Add(value); }
        }

        public override bool Test()
        {
            return Criterions.Any(criterion => criterion.Test());
        }
    }

    public sealed class OrCriterion : OrCriterion<object>
    {
    	public OrCriterion(params ICriterion[] criterions) : base(criterions)
    	{
    	}

    	public OrCriterion()
    	{
    	}
    }
}